import request from '@/utils/request'
import type { CatagaryResponseType, AttrResponseType, AttrType } from './types'
import type { catagrayIDs } from '../catagary/types'
enum API {
  CATAGARY_ONE_URL = '/admin/product/getCategory1',
  CATAGARY_TWO_URL = '/admin/product/getCategory2',
  CATAGARY_THREE_URL = '/admin/product/getCategory3',
  GETATTRLIST_URL = '/admin/product/attrInfoList',
  ADDORUPDATEATTR_URL = '/admin/product/saveAttrInfo',
  DELATTR_URL = '/admin/product/deleteAttr',
}

export const reqCatagaryOne = () =>
  request.get<any, CatagaryResponseType>(API.CATAGARY_ONE_URL)

export const reqCatagaryTwo = (id: number) =>
  request.get<any, CatagaryResponseType>(API.CATAGARY_TWO_URL + `/${id}`)

export const reqCatagaryThree = (id: number) =>
  request.get<any, CatagaryResponseType>(API.CATAGARY_THREE_URL + `/${id}`)

export const reqAttrList = (ids: catagrayIDs) =>
  request.get<any, AttrResponseType>(
    API.GETATTRLIST_URL + `/${ids.c1Id}` + `/${ids.c2Id}` + `/${ids.c3Id}`,
  )

export const reqAddOrUpdateAttr = (data: AttrType) =>
  request.post<any, any>(API.ADDORUPDATEATTR_URL, data)

export const reqDelAttr = (attrId: number) =>
  request.delete(API.DELATTR_URL + `/${attrId}`)
